https://leetcode.cn/problems/binary-tree-preorder-traversal/submissions/513053044/


int TreeSize(struct TreeNode* root)
{
    return root == NULL ? 0 : TreeSize(root->left) + TreeSize(root->right) + 1;
}
void _preorderTraversal(struct TreeNode* root, int* a, int* i)
{
    if (root == NULL)
    {
        return;
    }
    else
    {
        a[*i] = root->val;
        (*i)++;
        _preorderTraversal(root->left, a, i);
        _preorderTraversal(root->right, a, i);
    }
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    *returnSize = TreeSize(root);
    int* a = malloc(sizeof(int) * (*returnSize));
    int i = 0;
    _preorderTraversal(root, a, &i);
    return a;
}

